﻿using DAL3;
using HealthRooms.DataBaseOPerate.oductDataToDJ;
using Model;
using Model3._5;
using S7.Net;
using System;
using System.Data.SqlClient;
using System.IO;
using System.IO.Ports;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Data;
namespace GEMINI_OP50
{
    public partial class FormMain : Form
    {
        public string str = "未连接";
        //string strs = "";
        int PLC_Count = 1;
        Socket socketSend;
        public string server = "";
        string[] typeArray = new string[15];
        ////用于记录各个工位的扫码
        ////OP10-1
        //string[] EMArray10_1a = new string[15];
        //string[] EMArrayName10_1a = new string[15];
        //string[] EMArray10_1b = new string[15];
        //string[] EMArrayName10_1b = new string[15];
        //string[] EMArray10_1c = new string[15];
        //string[] EMArrayName10_1c = new string[15];
        //string[] EMArray10_1d = new string[15];
        //string[] EMArrayName10_1d = new string[15];
        ////OP10-2
        //string[] EMArray10_2a = new string[15];
        //string[] EMArrayName10_2a = new string[15];
        //string[] EMArray10_2b = new string[15];
        //string[] EMArrayName10_2b = new string[15];
        //string[] EMArray10_2c = new string[15];
        //string[] EMArrayName10_2c = new string[15];
        //string[] EMArray10_2d = new string[15];
        //string[] EMArrayName10_2d = new string[15];
        ////OP10
        //string[] EMArray10a = new string[15];
        //string[] EMArrayName10a = new string[15];
        //string[] EMArray10b = new string[15];
        //string[] EMArrayName10b = new string[15];
        //string[] EMArray10c = new string[15];
        //string[] EMArrayName10c = new string[15];
        //string[] EMArray10d = new string[15];
        //string[] EMArrayName10d = new string[15];
        ////OP20
        //string[] EMArray20a = new string[15];
        //string[] EMArrayName20a = new string[15];
        //string[] EMArray20b = new string[15];
        //string[] EMArrayName20b = new string[15];
        //string[] EMArray20c = new string[15];
        //string[] EMArrayName20c = new string[15];
        //string[] EMArray20d = new string[15];
        //string[] EMArrayName20d = new string[15];
        ////OP30
        //string[] EMArray30a = new string[15];
        //string[] EMArrayName30a = new string[15];
        //string[] EMArray30b = new string[15];
        //string[] EMArrayName30b = new string[15];
        //string[] EMArray30c = new string[15];
        //string[] EMArrayName30c = new string[15];
        //string[] EMArray30d = new string[15];
        //string[] EMArrayName30d = new string[15];
        ////OP40
        //string[] EMArray40a = new string[15];
        //string[] EMArrayName40a = new string[15];
        //string[] EMArray40b = new string[15];
        //string[] EMArrayName40b = new string[15];
        //string[] EMArray40c = new string[15];
        //string[] EMArrayName40c = new string[15];
        //string[] EMArray40d = new string[15];
        //string[] EMArrayName40d = new string[15];
        ////OP50
        //string[] EMArray50a = new string[15];
        //string[] EMArrayName50a = new string[15];
        //string[] EMArray50b = new string[15];
        //string[] EMArrayName50b = new string[15];
        //string[] EMArray50c = new string[15];
        //string[] EMArrayName50c = new string[15];
        //string[] EMArray50d = new string[15];
        //string[] EMArrayName50d = new string[15];
        ////OP60
        //string[] EMArray60a = new string[15];
        //string[] EMArrayName60a = new string[15];
        //string[] EMArray60b = new string[15];
        //string[] EMArrayName60b = new string[15];
        //string[] EMArray60c = new string[15];
        //string[] EMArrayName60c = new string[15];
        //string[] EMArray60d = new string[15];
        //string[] EMArrayName60d = new string[15];
        ////OP70
        //string[] EMArray70a = new string[15];
        //string[] EMArrayName70a = new string[15];
        //string[] EMArray70b = new string[15];
        //string[] EMArrayName70b = new string[15];
        //string[] EMArray70c = new string[15];
        //string[] EMArrayName70c = new string[15];
        //string[] EMArray70d = new string[15];
        //string[] EMArrayName70d = new string[15];
        //用于读取Debug内不同型号的扫码名称与识别内容
        string[] readSeting = new string[80];
        string[] saoma = new string[2];
        string icID;
        //string result;
        int num1;
        int num2;
        int ID;     //记录入返修表唯一数据，避免重复记录
        int Day;    //用时间作为ID前缀
        int Repairnumber;   //记录当天返修个数
        bool Repairnumber0;     //每天首次启动对Repairnumber进行清零操作
        public struct proData
        {
            public static string typeName;
            public static string Ewm;
            public static string testStation;
            public static string allResult;
            public static double positivePressureValue;
            public static double negativePressureValue;
            public static string operatorter;
            public static string serialNumber;
            public static bool save;
        }
        //public struct plcStructIn
        //{
        //    public bool bool_0;
        //    public bool bool_1;
        //    public bool bool_2;
        //    public bool bool_3;
        //    public bool bool_4;
        //    public bool bool_5;
        //    public bool bool_6;
        //    public bool bool_7;

        //    public byte byte_0;
        //    public byte byte_1;
        //    public byte byte_2;//生产型号
        //    public byte byte_3;
        //    public byte byte_4;
        //    public byte byte_5;

        //    public Int16 int_0;
        //    public Int16 int_1;
        //    public Int16 int_2;
        //    public Int16 int_3;
        //    public Int16 int_4;
        //    public Int16 int_5;
        //    public Int16 int_6;
        //    public Int16 int_7;

        //}
        //----线程循环
        bool _Continue = true;
        //----PLC监控线程数组
        //Thread[] PLC_Td;
        //PLC实例数组
        //public SimenesPLC[] PLC_Link;
        //PLC DB结构数组
        //public plcStructIn[] Struct_Test;
        //public static plcStructIn _plcStruct = new plcStructIn();     (返修台未连接PLC)

        public static FormMain FM10;
        public FormMain()
        {
            InitializeComponent();
            FM10 = (FormMain)this;
        }
        //private void OpenForm(Form form)
        //{
        //    //将当前子窗体设置成非顶级控件
        //    form.TopLevel = false;
        //    //设置窗体最大化
        //    form.WindowState = FormWindowState.Maximized;
        //    //设置窗体无边框
        //    form.FormBorderStyle = FormBorderStyle.None;
        //    //设置窗体嵌入容器
        //    form.Parent = this.panel1;
        //    form.Show();
        //}
        //private void CloseForm()
        //{
        //    //遍历这个容器里面的所有控件，找出窗体对象
        //    foreach (Control item in this.panel1.Controls)
        //    {
        //        if (item is Form)
        //        {
        //            Form form = (Form)item;
        //            form.Close();
        //            //移除
        //            this.panel1.Controls.Remove(item);
        //        }
        //    }
        //}

        private void button4_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //嵌入窗口
            //this.CloseForm();
            FormUserLoginInterface formUserLoginInterface = new FormUserLoginInterface();
            //this.OpenForm(formUserLoginInterface);
            formUserLoginInterface.Show();
        }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            //PLC_Link[0].plc.WriteBit(DataType.DataBlock, 99, 190, 4, 0);
            ////关闭主窗体时释放后台线程的资源
            //for (int I = 0; I < PLC_Count; I++)
            //{
            //    if (PLC_Td[I] != null)
            //    {
            //        PLC_Td[I].Abort();
            //    }
            //}
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;  //启用计时器
            //取消跨线程的访问
            Control.CheckForIllegalCrossThreadCalls = false;
            //#region 连接PLC
            //PLC_Td = new Thread[PLC_Count];
            //PLC_Link = new SimenesPLC[PLC_Count];
            ////Struct_Test = new plcStructIn[PLC_Count];
            //for (int I = 0; I < PLC_Count; I++)
            //{
            //    PLC_Td[I] = new Thread(PLC_Td_Func);
            //    PLC_Td[I].IsBackground = true;
            //    PLC_Td[I].Start(I);
            //}
            //#endregion

            #region 与服务器tcp/ip通讯建立连接
            try
            {
                //创建负责通信的Socket
                socketSend = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress ip = IPAddress.Parse("192.168.1.150");
                IPEndPoint point = new IPEndPoint(ip, 50001);
                //获得要连接的远程服务器应用程序的IP地址和端口号
                socketSend.Connect(point);
                server = "成功";

                //开启一个新的线程不停的接收服务端发来的消息
                Thread th = new Thread(Recive);
                th.IsBackground = true;
                th.Start();
            }
            catch
            {
                server = "失败";
            }
            #endregion

            #region 设置串口参数并打开串口接收
            //波特率

            //IC卡
            //serialPort1.BaudRate = 9600;
            //扫码
            serialPort2.BaudRate = 115200;

            //数据位

            //IC卡
            //serialPort1.DataBits = 8;
            //扫码
            serialPort2.DataBits = 8;

            //奇偶校验位
            //serialPort1.Parity = System.IO.Ports.Parity.None;
            serialPort2.Parity = System.IO.Ports.Parity.None;

            //停止位
            //serialPort1.StopBits = System.IO.Ports.StopBits.One;
            serialPort2.StopBits = System.IO.Ports.StopBits.One;

            string[] contents = new string[5];
            try
            {
                contents = File.ReadAllLines(Application.StartupPath + "\\COM口配置.txt", Encoding.UTF8);
            }
            catch
            {
                label28.Text += "请检查COM口配置文件！";
            }
            //端口
            //try
            //{
            //    serialPort1.PortName = contents[0];
            //    serialPort1.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
            //    serialPort1.Open();

            //}
            //catch
            //{
            //    MessageBox.Show("IC卡端口打开失败，请检查串口连接是否正确！", "错误提示");
            //}

            try
            {
                serialPort2.PortName = contents[1];
                serialPort2.DataReceived += new SerialDataReceivedEventHandler(SerialPort2_DataReceived);
                serialPort2.Open();
            }
            catch
            {
                MessageBox.Show("扫码端口打开失败，请检查串口连接是否正确！", "错误提示");
            }
            #endregion
        }
        //PLC线程
        int[] screwRecordingCompleted = new int[20];
        private void PLC_Td_Func(object ob)
        {
            Ping p = new Ping();
            int num = (int)ob;

            string[] PLC_IP = new string[PLC_Count];
            PLC_IP[0] = "172.16.1.2";
            //PLC_Link[num] = new SimenesPLC(CpuType.S71200, PLC_IP[num].ToString(), 0, 1);
            while (_Continue)
            {
                try
                {
                    //处理相应的PLC对象的数据处理
                    if (p.Send(PLC_IP[num], 200).Status == IPStatus.Success)//如果200ms时间间隔ping通了
                    {
                        //if (PLC_Link[num].plc.IsConnected == false)//plc没有连接上
                        //{
                        //    //int s = (int)PLC_Link[num].plc.Open();
                        //    //strs = Convert.ToString(s);
                        //    //if (s == 0)
                        //    //{
                        //    //    str = "成功";
                        //    //    SimenesPLC.conectStatus = true;
                        //    //}
                        //    //else
                        //    //{
                        //    //    str = "失败";
                        //    //    SimenesPLC.conectStatus = false;
                        //    //}
                        //    try
                        //    {
                        //        PLC_Link[0].plc.Open();
                        //        SimenesPLC.conectStatus = true;
                        //        str = "成功";
                        //    }
                        //    catch (Exception)
                        //    {
                        //        SimenesPLC.conectStatus = false;
                        //        str = "失败";
                        //        //throw;
                        //    }
                        //}
                        //else
                        //{
                            str = "成功";
                            //读取DB
                            //Struct_Test[num] = (plcStructIn)PLC_Link[num].plc.ReadStruct(typeof(plcStructIn), 99, 392);
                            //_plcStruct = Struct_Test[num];
                            //string ID = PLC_Link[num].plc.Read(DataType.DataBlock, 99, 416, VarType.DInt, 1).ToString();
                            //label11.Text = _plcStruct.byte_0.ToString();
                            //label10.Text = _plcStruct.byte_1.ToString();
                            //打钉扭力记录
                            //try
                            //{
                                //switch (_plcStruct.byte_1)
                                //{
                                //    case 1:
                                //        if (screwRecordingCompleted[0] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉1扭力]='{0}',[螺钉1角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[0] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 2:
                                //        if (screwRecordingCompleted[1] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉2扭力]='{0}',[螺钉2角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[1] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 3:
                                //        if (screwRecordingCompleted[2] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉3扭力]='{0}',[螺钉3角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[2] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 4:
                                //        if (screwRecordingCompleted[3] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉4扭力]='{0}',[螺钉4角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[3] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 5:
                                //        if (screwRecordingCompleted[4] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉5扭力]='{0}',[螺钉5角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[4] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 6:
                                //        if (screwRecordingCompleted[5] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉6扭力]='{0}',[螺钉6角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[5] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 7:
                                //        if (screwRecordingCompleted[6] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉7扭力]='{0}',[螺钉7角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[6] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 8:
                                //        if (screwRecordingCompleted[7] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉8扭力]='{0}',[螺钉8角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[7] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 9:
                                //        if (screwRecordingCompleted[8] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉9扭力]='{0}',[螺钉9角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[8] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //    case 10:
                                //        if (screwRecordingCompleted[9] == 0)
                                //        {
                                //            string sql = "update repair set [螺钉10扭力]='{0}',[螺钉10角度]='{1}' where [内部码] = '{2}'";
                                //            sql = string.Format(sql, label43.Text, label44.Text, label20.Text);
                                //            screwRecordingCompleted[9] = SQLHelp.AddData(sql);
                                //        }
                                //        break;
                                //        //case 11:
                                //        //    if (screwRecordingCompleted[10] == 0)
                                //        //    {
                                //        //        string sql = "update productData set [OP50螺钉11扭力]='{0}',[OP50螺钉11角度]='{1}' where [ID] = '{2}'";
                                //        //        sql = string.Format(sql, label43.Text, label44.Text, ID);
                                //        //        screwRecordingCompleted[10] = SQLHelp.AddData(sql);
                                //        //    }
                                //        //    break;
                                //}
                                //if (Convert.ToInt32(PLC_Link[0].plc.Read(DataType.DataBlock, 99, 384, VarType.Word, 1, 0)) == 0)
                                //{
                                //dading();
                                //if (_plcStruct.byte_0 + _plcStruct.byte_1 > 0)
                                //{
                                //    //List<Label> lab = new List<Label> { useTable1, useTable2, useTable3, useTable4, useTable5, useTable6, useTable7, useTable8, useTable9, useTable10, useTable11, useTable12, useTable13, useTable14, useTable15, useTable16, useTable17, useTable18, useTable19 };
                                //    //for (int i = 0; i < _plcStruct.byte_0 + _plcStruct.byte_1; i++)
                                //    //{
                                //    //    lab[i].BackColor = Color.Green;
                                //    //}
                                //}
                                //else if (_plcStruct.byte_0 + _plcStruct.byte_1 == 0)
                                //{
                                //    //List<Label> lab = new List<Label> { useTable1, useTable2, useTable3, useTable4, useTable5, useTable6, useTable7, useTable8, useTable9, useTable10, useTable11, useTable12, useTable13, useTable14, useTable15, useTable16, useTable17, useTable18, useTable19 };
                                //    //for (int i = 0; i < 19; i++)
                                //    //{
                                //    //    lab[i].BackColor = Color.Yellow;
                                //    //}
                                //}
                                //}
                            //}
                            //catch (Exception)
                            //{

                                //throw;
                            //}
                        //}
                    }
                    else
                    {
                        //PLC_Link[num].plc.Close();
                        str = "ping失败";
                    }
                    if (p.Send("192.168.1.150", 200).Status == IPStatus.Success)
                    {
                        server = "成功";
                    }
                    else
                    {
                        server = "ping失败";
                    }
                }
                catch (Exception ex1)
                {
                    //str = "出现异常";
                    MessageBox.Show(Convert.ToString(ex1), "错误提示!");
                }

                if (str.Equals("成功"))
                {
                    label23.BackColor = System.Drawing.Color.Green;
                }
                else
                {
                    label23.BackColor = System.Drawing.Color.Red;
                }
                if (server.Equals("成功"))
                {
                    label22.BackColor = System.Drawing.Color.Green;
                }
                else
                {
                    label22.BackColor = System.Drawing.Color.Red;
                }
                //Thread.Sleep(100);
                //label18.Text = DateTime.Now.ToString("yyyy/MM/dd");
                //label19.Text = DateTime.Now.ToLongTimeString();
                //label242.Text = "使用公司：空调国际(上海)有限公司   \t 设备公司：重庆英之拓智能设备有限公司  \t  软件版本号：V2.0";
                //label242.Text = string.Format(label242.Text, Program.userlogin.name);
            }

        }

        void Recive()
        {
            while (true)
            {
                try
                {
                    byte[] buffer = new byte[1024];
                    int r = socketSend.Receive(buffer);
                    //实际接收到的有效字节数
                    if (r == 0)
                    {
                        break;
                    }
                    //表示发送的字符消息,并且是所有产品型号
                    if (buffer[0] == 0)
                    {
                        string s = Encoding.UTF8.GetString(buffer, 1, r - 1);

                        //0 5 ,aaa,asas,dsds,gfhh,hhggh,
                        //截取所有型号
                        typeArray = s.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    }
                    //表示发送的字符消息,并且是扫码参数
                    if (buffer[0] == 1)
                    {
                        string s = Encoding.UTF8.GetString(buffer, 1, r - 1);
                        //1,hhggh
                        //截取扫码参数设置
                        saoma = s.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    }
                    //else if (buffer[0] == 1)
                    //{
                    //    SaveFileDialog sfd = new SaveFileDialog();
                    //    sfd.InitialDirectory = @"C:\Users\SpringRain\Desktop";
                    //    sfd.Title = "请选择要保存的文件";
                    //    sfd.Filter = "所有文件|*.*";
                    //    sfd.ShowDialog(this);
                    //    string path = sfd.FileName;
                    //    using (FileStream fsWrite = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
                    //    {
                    //        fsWrite.Write(buffer, 1, r - 1);
                    //    }
                    //    MessageBox.Show("保存成功");
                    //}
                    //else if (buffer[0] == 2)
                    //{
                    //    ZD();
                    //}

                }
                catch { }

            }
        }

        //IC卡
        private void SerialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {

                Thread.Sleep(50);
                byte[] byteRead1 = new byte[serialPort1.BytesToRead];
                serialPort1.Read(byteRead1, 0, byteRead1.Length);
                byte[] temp6 = new byte[1];
                temp6[0] = byteRead1[20];
                icID = byteToHexStr(temp6, 1);
                Program.userlogin = UserManagement.GetUser(Convert.ToInt32(icID));
                label242.Text = "当前登录用户：{0} \t\t  使用公司：空调国际(上海)有限公司   \t 设备公司：重庆英之拓智能设备有限公司  \t  软件版本号：V1.0";
                label242.Text = string.Format(label242.Text, Program.userlogin.name);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc + "接收失败");
            }

        }
        //扫码枪
        //bool tempEM1ok;
        //bool tempEM2ok;
        //bool tempEM3ok;
        //bool tempEM4ok;
        string internalCode;
        string OP70Result;
        string OP80Result;
        string OP90Result;
        string OP100Result;
       
        string[] TypeName=new string[40];
        string[] TypePrefix = new string[40];


        private void NamePrefixInquire(string type)
        {
            string sqltype = "select [OP10扫码1名称],[OP10扫码1],[OP10扫码2名称],[OP10扫码2], [OP10扫码3名称],[OP10扫码3], [OP10扫码4名称],[OP10扫码4], [OP20扫码1名称],[OP20扫码1], [OP20扫码2名称],[OP20扫码2], [OP20扫码3名称],[OP20扫码3],[OP20扫码4名称],[OP20扫码4],[OP30扫码1名称],[OP30扫码1], [OP30扫码2名称],[OP30扫码2],[OP30扫码3名称],[OP30扫码3],[OP30扫码4名称],[OP30扫码4], [OP40扫码1名称],[OP40扫码1], [OP40扫码2名称],[OP40扫码2], [OP40扫码3名称],[OP40扫码3],[OP40扫码4名称],[OP40扫码4],[OP50扫码1名称],[OP50扫码1], [OP50扫码2名称],[OP50扫码2], [OP50扫码3名称],[OP50扫码3], [OP50扫码4名称],[OP50扫码4], [OP60扫码1名称],[OP60扫码1], [OP60扫码2名称],[OP60扫码2], [OP60扫码3名称],[OP60扫码3], [OP60扫码4名称],[OP60扫码4], [OP70扫码1名称]  from parameterSetting where [typeName] = '{0}'";     //,[OP70扫码1], [OP70扫码2名称],[OP70扫码2], [OP70扫码3名称],[OP70扫码3], [OP70扫码4名称],[OP70扫码4]
            sqltype = string.Format(sqltype, type);
            SqlDataReader objReaderType = SQLHelp.GetReader(sqltype);
            //循环写入数据
            while (objReaderType.Read())
            {
                TypeName[0] = objReaderType["OP10扫码1名称"].ToString();
                TypeName[1] = objReaderType["OP10扫码2名称"].ToString();
                TypeName[2] = objReaderType["OP10扫码3名称"].ToString();
                TypeName[3] = objReaderType["OP10扫码4名称"].ToString();
                TypeName[4] = objReaderType["OP20扫码1名称"].ToString();
                TypeName[5] = objReaderType["OP20扫码2名称"].ToString();
                TypeName[6] = objReaderType["OP20扫码3名称"].ToString();
                TypeName[7] = objReaderType["OP20扫码4名称"].ToString();
                TypeName[8] = objReaderType["OP30扫码1名称"].ToString();
                TypeName[9] = objReaderType["OP30扫码2名称"].ToString();
                TypeName[10] = objReaderType["OP30扫码3名称"].ToString();
                TypeName[11] = objReaderType["OP30扫码4名称"].ToString();
                TypeName[12] = objReaderType["OP40扫码1名称"].ToString();
                TypeName[13] = objReaderType["OP40扫码2名称"].ToString();
                TypeName[14] = objReaderType["OP40扫码3名称"].ToString();
                TypeName[15] = objReaderType["OP40扫码4名称"].ToString();
                TypeName[16] = objReaderType["OP50扫码1名称"].ToString();
                TypeName[17] = objReaderType["OP50扫码2名称"].ToString();
                TypeName[18] = objReaderType["OP50扫码3名称"].ToString();
                TypeName[19] = objReaderType["OP50扫码4名称"].ToString();
                TypeName[20] = objReaderType["OP60扫码1名称"].ToString();
                TypeName[21] = objReaderType["OP60扫码2名称"].ToString();
                TypeName[22] = objReaderType["OP60扫码3名称"].ToString();
                TypeName[23] = objReaderType["OP60扫码4名称"].ToString();
                //TypeName[24] = objReaderType["OP70扫码1名称"].ToString();
                //TypeName[25] = objReaderType["OP70扫码2名称"].ToString();
                //TypeName[26] = objReaderType["OP70扫码3名称"].ToString();
                //TypeName[27] = objReaderType["OP70扫码4名称"].ToString();
                TypeName[28] = readSeting[0];
                TypeName[29] = readSeting[2];
                TypeName[30] = readSeting[4];
                TypeName[31] = readSeting[6];
                //TypeName[32] = objReaderType["OP10_2扫码1名称"].ToString();
                //TypeName[33] = objReaderType["OP10_2扫码2名称"].ToString();
                //TypeName[34] = objReaderType["OP10_2扫码3名称"].ToString();
                //TypeName[35] = objReaderType["OP10_2扫码4名称"].ToString();

                TypePrefix[0] = objReaderType["OP10扫码1"].ToString();
                TypePrefix[1] = objReaderType["OP10扫码2"].ToString();
                TypePrefix[2] = objReaderType["OP10扫码3"].ToString();
                TypePrefix[3] = objReaderType["OP10扫码4"].ToString();
                TypePrefix[4] = objReaderType["OP20扫码1"].ToString();
                TypePrefix[5] = objReaderType["OP20扫码2"].ToString();
                TypePrefix[6] = objReaderType["OP20扫码3"].ToString();
                TypePrefix[7] = objReaderType["OP20扫码4"].ToString();
                TypePrefix[8] = objReaderType["OP30扫码1"].ToString();
                TypePrefix[9] = objReaderType["OP30扫码2"].ToString();
                TypePrefix[10] = objReaderType["OP30扫码3"].ToString();
                TypePrefix[11] = objReaderType["OP30扫码4"].ToString();
                TypePrefix[12] = objReaderType["OP40扫码1"].ToString();
                TypePrefix[13] = objReaderType["OP40扫码2"].ToString();
                TypePrefix[14] = objReaderType["OP40扫码3"].ToString();
                TypePrefix[15] = objReaderType["OP40扫码4"].ToString();
                TypePrefix[16] = objReaderType["OP50扫码1"].ToString();
                TypePrefix[17] = objReaderType["OP50扫码2"].ToString();
                TypePrefix[18] = objReaderType["OP50扫码3"].ToString();
                TypePrefix[19] = objReaderType["OP50扫码4"].ToString();
                TypePrefix[20] = objReaderType["OP60扫码1"].ToString();
                TypePrefix[21] = objReaderType["OP60扫码2"].ToString();
                TypePrefix[22] = objReaderType["OP60扫码3"].ToString();
                TypePrefix[23] = objReaderType["OP60扫码4"].ToString();
                //TypePrefix[24] = objReaderType["OP70扫码1"].ToString();
                //TypePrefix[25] = objReaderType["OP70扫码2"].ToString();
                //TypePrefix[26] = objReaderType["OP70扫码3"].ToString();
                //TypePrefix[27] = objReaderType["OP70扫码4"].ToString();
                TypePrefix[28] = readSeting[1];
                TypePrefix[29] = readSeting[3];
                TypePrefix[30] = readSeting[5];
                TypePrefix[31] = readSeting[7];
                //TypePrefix[32] = objReaderType["OP10_2扫码1"].ToString();
                //TypePrefix[33] = objReaderType["OP10_2扫码2"].ToString();
                //TypePrefix[34] = objReaderType["OP10_2扫码3"].ToString();
                //TypePrefix[35] = objReaderType["OP10_2扫码4"].ToString();
            }
            objReaderType.Close();
        }

        private void SerialPort2_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                Thread.Sleep(100);
                byte[] byteRead = new byte[serialPort2.BytesToRead];
                serialPort2.Read(byteRead, 0, byteRead.Length);
                string indata = Encoding.UTF8.GetString(byteRead);
                label13.Text = indata;      //当前扫码
              
                if ((indata.Substring(0, 5).Contains("DIDI") || indata.Substring(0, 5).Contains("D01")) || indata.Substring(0, 5).Contains("BF") || indata.Substring(0, 5).Contains("BR"))     //内部码为DIDI2开头
                {
                    label20.Text = indata;
                    label20.BackColor = System.Drawing.Color.Green;
                    button2.BackColor = System.Drawing.Color.Silver;
                    label13.BackColor = System.Drawing.Color.Silver;
                    if (label20.Text.Substring(0, 5).Contains("DIDI") || indata.Substring(0, 5).Contains("D01"))
                    {
                        comboBox2.Text = "DIDI";
                        NamePrefixInquire("DIDI");
                        //readSeting = File.ReadAllLines(Application.StartupPath + "\\" + "型号" + "\\" + comboBox2.Text + ".txt", Encoding.UTF8);
                        readTxt(comboBox2.Text);
                    }
                    else if (label20.Text.Substring(0, 5).Contains("BF"))
                    {
                        comboBox2.Text = "百度前空调";
                        NamePrefixInquire("百度前空调");
                        //readSeting = File.ReadAllLines(Application.StartupPath + "\\" + "型号" + "\\" + comboBox2.Text + ".txt", Encoding.UTF8);
                        readTxt(comboBox2.Text);
                    }
                    else if (label20.Text.Substring(0, 5).Contains("BR"))
                    {
                        comboBox2.Text = "百度后空调";
                        NamePrefixInquire("百度后空调");
                        //readSeting = File.ReadAllLines(Application.StartupPath + "\\" + "型号" + "\\" + comboBox2.Text + ".txt", Encoding.UTF8);
                        readTxt(comboBox2.Text);
                    }
                    else
                    {
                        label28.Text = "内部码不匹配";
                    }

                    string sql = "select [总成码],[产品下线时间] from productData where [内部码] = '" + label20.Text + "' order by [产品下线时间] DESC";
                    //string sql = "select [总成码],[OP70结果],[OP80结果],[OP90结果],[OP100结果],[产品下线时间] from productData where [内部码] = '" + label20.Text+ "' order by [产品下线时间] DESC";
                    Day = Convert.ToInt32(System.DateTime.Now.ToString("yyyy")) * 1000000 + Convert.ToInt32(System.DateTime.Now.ToString("MM")) * 10000 + Convert.ToInt32(System.DateTime.Now.ToString("dd")) * 100;
                    //SELECT CONCAT(id, ', ', username, ', ', email, ', ', phone) as user_info FROM users WHERE id = 1;
                    //string sql2 = "Select CONCAT(id, ', ', username, ', ', email, ', ', phone) as user_info from productData WHERE id = 1";
                    try
                    {
                        SqlDataReader objReader = SQLHelp.GetReader(sql);
                        //循环写入数据
                        while (objReader.Read())
                        {
                            internalCode = objReader["总成码"].ToString();
                        }
                        objReader.Close();
     
                    }
                    catch (Exception a)
                    {
                        internalCode = "o";
                        MessageBox.Show("查询失败！请到终端机查询该条码" + a.ToString());
                    }
                    //初始化Repairnumber，每次打开比较ID,避免出现重复无法记录入返修表。
                    if (!Repairnumber0)
                    {
                        string sql1 = "SELECT TOP 1 [ID] FROM repair order by id desc";
                        SqlDataReader objReader1 = SQLHelp.GetReader(sql1);
                        while (objReader1.Read())
                        {

                            int a = Convert.ToInt32(objReader1["ID"]);
                            if (a < Day)
                            {
                                Repairnumber = 0;
                            }
                            else
                            {
                                Repairnumber = a - Day + 1;
                            }
                        }
                        objReader1.Close();
                        Repairnumber0 = true;
                    }
                    else
                    {
                        label28.Text = "非打开软件首次进行返修";
                    }
                    //System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")
                    //Day = Convert.ToInt32(System.DateTime.Now.ToString("yyyy")) * 1000000 + Convert.ToInt32(System.DateTime.Now.ToString("MM")) * 10000 + Convert.ToInt32(System.DateTime.Now.ToString("dd"))*100;
                    //label28.Text = /*System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")*/Day.ToString();
                    ID = Day + Repairnumber++;
                    //label28.Text = ID.ToString();
                    label1.Text = internalCode.Contains("OP70") ? "OP70不合格" : internalCode.Contains("OP80") ? "OP80不合格" : internalCode.Contains("OP90") ? "OP90不合格" : internalCode.Contains("OP100") ? "OP100不合格" : "未查询到不合格";  //气检(OP70)、电检(OP80)、人工检(OP100)不合格。

                    if (!label1.Text.Contains("未查询到不合格"))
                    {
                        string sql1 = "insert into repair([内部码], [ID]) values('{0}','{1}')";        //左repair表中插入新的内部码为label20.Text的行。
                        sql1 = string.Format(sql1, label20.Text, ID);
                        num1 = SQLHelp.AddData(sql1);
                    }




                    //readTxt(internalCode.Contains("OP70") ? "OP70" : internalCode.Contains("OP80") ? "OP80" : internalCode.Contains("OP100") ? "OP100" : "0");
                    //readTxt("0");
                }
                //有内部码且选定了需更换零件才进行数据零件码记录到操作
                else if (!(label20.Text == "") && (butDownArry[0] || butDownArry[1] || butDownArry[2] || butDownArry[3] || butDownArry[4] || butDownArry[5] || butDownArry[6] || butDownArry[7] || butDownArry[8] || butDownArry[9] || butDownArry[10] || butDownArry[11] || butDownArry[12] || butDownArry[13] || butDownArry[14] || butDownArry[15] || butDownArry[16] || butDownArry[17] || butDownArry[18] || butDownArry[19] || butDownArry[20] || butDownArry[21] || butDownArry[22] || butDownArry[23] || butDownArry[24] || butDownArry[25] || butDownArry[26] || butDownArry[27] || butDownArry[28] || butDownArry[29] || butDownArry[30] || butDownArry[31] || butDownArry[32] || butDownArry[33] || butDownArry[34] || butDownArry[35]))      //扫新的零件码时更新零件码，并记录至返修内容
                {
                    label13.BackColor = System.Drawing.Color.Silver;
                    label6.Text = indata;
                    int num3;       //num3用于零件码记录
                    if (butDownArry[0] && label6.Text.Contains(TypePrefix[0]))     //OP10扫码1 
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";
                        //string sql1 = "update tiaoma set [返修内容] ='{0}'where [内部码] = '{1}'";
                        //sql1 = string.Format(label7.Text, label20.Text);
                        //num2 = SQLHelp.AddData(sql1);    

                        string sql = "update tiaoma set [OP10扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[0] = false;
                            //button5.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[1] && label6.Text.Contains(TypePrefix[1]))     //OP10扫码2  
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[1] = false;
                            //button6.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }

                    }
                    else if (butDownArry[2] && label6.Text.Contains(TypePrefix[2]))     //OP10扫码3
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10扫码3] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[1] = false;
                            //button6.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[3] && label6.Text.Contains(TypePrefix[3]))     //OP10扫码4
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10扫码4] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数

                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[1] = false;
                            //button6.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[4] && label6.Text.Contains(TypePrefix[4]))     //OP20扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP20扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[2] = false;
                            //button9.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[5] && label6.Text.Contains(TypePrefix[5]))     //OP20扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP20扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[3] = false;
                            //button10.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[6] && label6.Text.Contains(TypePrefix[6]))     //OP20扫码3 
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP20扫码3] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[4] = false;
                            //button11.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[7] && label6.Text.Contains(TypePrefix[7]))     //OP20扫码4
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP20扫码4] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[5] = false;
                            //button12.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[8] && label6.Text.Contains(TypePrefix[8]))     //OP30扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP30扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[6] = false;
                            //button13.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[9] && label6.Text.Contains(TypePrefix[9]))     //OP30扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP30扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[7] = false;
                            //button14.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[10] && label6.Text.Contains(TypePrefix[10]))     //OP30扫码3
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP30扫码3] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[8] = false;
                            //button15.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[11] && (label6.Text.Contains(TypePrefix[11])))     //OP30扫码4
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP30扫码4] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[9] = false;
                            //button16.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }

                    }


                    else if (butDownArry[12] && label6.Text.Contains(TypePrefix[12]))     //OP40扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP40扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[10] = false;
                            //button17.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }

                    }
                    else if (butDownArry[13] && label6.Text.Substring(0, 5).Contains(TypePrefix[13]))     //OP40扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP40扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[11] = false;
                            //button18.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[14] && label6.Text.Contains(TypePrefix[14]))     //OP40扫码3
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP40扫码3] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[12] = false;
                            //button19.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }


                    }
                    else if (butDownArry[15] && label6.Text.Contains(TypePrefix[15]))     //OP40扫码4
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";
                        string sql = "update tiaoma set [OP40扫码4] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[13] = false;
                            //button21.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[16] && label6.Text.Contains(TypePrefix[16]))     //OP50扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";
                        
                        string sql = "update tiaoma set [OP50扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[14] = false;
                            //button23.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }

                    }
                    else if (butDownArry[17] && label6.Text.Contains(TypePrefix[17]))     //OP50扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP50扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[14] = false;
                            //button23.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }

                    }
                    else if (butDownArry[18] && label6.Text.Contains(TypePrefix[18]))     //OP50扫码3
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";
                        
                        string sql = "update tiaoma set [OP50扫码3] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[15] = false;
                            //button25.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[19] && label6.Text.Contains(TypePrefix[19]))     //OP50扫码4
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP50扫码4] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[14] = false;
                            //button23.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[20] && label6.Text.Contains(TypePrefix[20]))     //OP60扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP60扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[14] = false;
                            //button23.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[21] && label6.Text.Contains(TypePrefix[21]))     //OP60扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP60扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[14] = false;
                            //button23.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[22] && label6.Text.Contains(TypePrefix[22]))     //OP60扫码3
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP60扫码3] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[14] = false;
                            //button23.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[23] && label6.Text.Contains(TypePrefix[23]))     //OP60扫码4
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";
                        
                        string sql = "update tiaoma set [OP60扫码4] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[16] = false;
                            //button27.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    //else if (butDownArry[24] && label6.Text.Contains(TypePrefix[24]))     //OP70扫码1
                    //{
                    //    label6.BackColor = System.Drawing.Color.Green;
                    //    label7.Text += label6.Text + ",";

                    //    string sql = "update tiaoma set [OP70扫码1] ='{0}'where [内部码] = '{1}'";
                    //    sql = string.Format(sql, label6.Text, label20.Text);
                    //    num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                    //    if (num3 == 1)
                    //    {
                    //        label6.Text = "";
                    //        label6.BackColor = System.Drawing.Color.Silver;
                    //        //butDownArry[16] = false;
                    //        //button27.BackColor = System.Drawing.Color.Silver;
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("请确认内部码是否为返修件");
                    //        return;
                    //    }
                    //}
                    //else if (butDownArry[25] && label6.Text.Contains(TypePrefix[25]))     //OP70扫码2
                    //{
                    //    label6.BackColor = System.Drawing.Color.Green;
                    //    label7.Text += label6.Text + ",";

                    //    string sql = "update tiaoma set [OP70扫码2] ='{0}'where [内部码] = '{1}'";
                    //    sql = string.Format(sql, label6.Text, label20.Text);
                    //    num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                    //    if (num3 == 1)
                    //    {
                    //        label6.Text = "";
                    //        label6.BackColor = System.Drawing.Color.Silver;
                    //        //butDownArry[16] = false;
                    //        //button27.BackColor = System.Drawing.Color.Silver;
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("请确认内部码是否为返修件");
                    //        return;
                    //    }
                    //}
                    //else if (butDownArry[26] && label6.Text.Contains(TypePrefix[26]))     //OP70扫码3
                    //{
                    //    label6.BackColor = System.Drawing.Color.Green;
                    //    label7.Text += label6.Text + ",";

                    //    string sql = "update tiaoma set [OP70扫码3] ='{0}'where [内部码] = '{1}'";
                    //    sql = string.Format(sql, label6.Text, label20.Text);
                    //    num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                    //    if (num3 == 1)
                    //    {
                    //        label6.Text = "";
                    //        label6.BackColor = System.Drawing.Color.Silver;
                    //        //butDownArry[16] = false;
                    //        //button27.BackColor = System.Drawing.Color.Silver;
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("请确认内部码是否为返修件");
                    //        return;
                    //    }
                    //}
                    //else if (butDownArry[27] && label6.Text.Contains(TypePrefix[27]))     //OP70扫码4
                    //{
                    //    label6.BackColor = System.Drawing.Color.Green;
                    //    label7.Text += label6.Text + ",";

                    //    string sql = "update tiaoma set [OP70扫码4] ='{0}'where [内部码] = '{1}'";
                    //    sql = string.Format(sql, label6.Text, label20.Text);
                    //    num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                    //    if (num3 == 1)
                    //    {
                    //        label6.Text = "";
                    //        label6.BackColor = System.Drawing.Color.Silver;
                    //        //butDownArry[16] = false;
                    //        //button27.BackColor = System.Drawing.Color.Silver;
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("请确认内部码是否为返修件");
                    //        return;
                    //    }
                    //}
                    else if (butDownArry[28] && label6.Text.Contains(readSeting[1]))     //OP10-1扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10-1扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[16] = false;
                            //button27.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[29] && label6.Text.Contains(readSeting[3]))     //OP10-1扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10-1扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[16] = false;
                            //button27.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[30] && label6.Text.Contains(readSeting[5]))     //OP10-2扫码1
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10-2扫码1] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[16] = false;
                            //button27.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    else if (butDownArry[31] && label6.Text.Contains(readSeting[7]))     //OP10-2扫码2
                    {
                        label6.BackColor = System.Drawing.Color.Green;
                        label7.Text += label6.Text + ",";

                        string sql = "update tiaoma set [OP10-2扫码2] ='{0}'where [内部码] = '{1}'";
                        sql = string.Format(sql, label6.Text, label20.Text);
                        num3 = SQLHelp.AddData(sql);        //SQLHelp.AddData() 返回受影响的行数
                        if (num3 == 1)
                        {
                            label6.Text = "";
                            label6.BackColor = System.Drawing.Color.Silver;
                            //butDownArry[16] = false;
                            //button27.BackColor = System.Drawing.Color.Silver;
                        }
                        else
                        {
                            MessageBox.Show("请确认内部码是否为返修件");
                            return;
                        }
                    }
                    //label20.Text = indata;
                    //label20.BackColor = System.Drawing.Color.Red;

                    else        //无内部码，且没选择返修零件
                    {
                        label13.BackColor = System.Drawing.Color.Red;
                    }
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc + "接收失败");
            }
            
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            //Thread.Sleep(100); System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")
            label18.Text = System.DateTime.Now.ToString("yyyy/MM/dd");      //23/6/26 时间无法显示，待查找问题
            label19.Text = System.DateTime.Now.ToString("HH:mm:ss");
            label242.Text = "使用公司：空调国际(上海)有限公司   \t 设备公司：重庆英之拓智能设备有限公司  \t  软件版本号：V2.0";

            //Ping p = new Ping();
            //if (p.Send("192.168.1.150", 200).Status == IPStatus.Success)      //暂时无法直接ping
            //{
            //    server = "成功";
            //}
            //else
            //{
            //    server = "ping失败";
            //}
            //if (server.Equals("成功"))                          //暂时无法获得连接“成功”
            //{
            //    label22.BackColor = System.Drawing.Color.Green;
            //}
            //else
            //{
            //    label22.BackColor = System.Drawing.Color.Red;
            //}
        }
        public string byteToHexStr(byte[] bytes, int len)  //数组转十六进制字符
        {
            string returnStr = "";
            if (bytes != null)
            {
                for (int i = 0; i < len; i++)
                {
                    returnStr += bytes[i].ToString("X2");   //X表示十六进制，2表示每次都是两位。.ToString("X2")表示每次都输出两位十六进制数
                }
            }
            return returnStr;
        }
        private static byte[] strToToHexByte(string hexString) //字符串转16进制
        {
            //hexString = hexString.Replace(" ", " "); 
            if ((hexString.Length % 2) != 0)
                hexString = "0" + hexString;
            byte[] returnBytes = new byte[hexString.Length / 2];
            for (int i = 0; i < returnBytes.Length; i++)
                returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
            return returnBytes;
        }
        
        static string GetLatestFileNameInfo(string dir, string ext)
        {
            DirectoryInfo d = new DirectoryInfo(dir);
            DateTime temp = new DateTime();
            string FileName = "0";
            foreach (FileInfo file in d.GetFiles())
            {
                if (file.Extension.ToUpper() == ext.ToUpper())
                {
                    if (file.CreationTime > temp)
                    {
                        temp = file.CreationTime;
                        FileName = file.FullName;
                    }
                }
            }

            return FileName;
        }
        //public void readTxt(string s)
        //{
        //    if (!s.Equals(0))
        //    {
        //        string s1 = File.ReadAllText(s + ".txt");   //打开s.txt (s = 70/80/90)
        //        partName = s1.Split(new Char[] { '，' }, StringSplitOptions.RemoveEmptyEntries);     //基于“，”将字符串拆成多个量，并赋给字符串组partName
        //        button5.Text = partName[0];
        //        button6.Text = partName[1];
        //        button9.Text = partName[2];
        //        button10.Text = partName[3];
        //        button11.Text = partName[4];
        //        button12.Text = partName[5];
        //        button13.Text = partName[6];
        //        button14.Text = partName[7];
        //        button15.Text = partName[8];
        //        button16.Text = partName[9];
        //        button17.Text = partName[10];
        //        button18.Text = partName[11];
        //        button19.Text = partName[12];
        //        button21.Text = partName[13];
        //        button23.Text = partName[14];
        //        button25.Text = partName[15];
        //        button27.Text = partName[16];
        //        button29.Text = partName[17];
        //        button31.Text = partName[18];
        //        button37.Text = partName[19];
        //        button43.Text = partName[20];
        //    }
        //}
        //用于给各个按钮赋值文本与条码识别内容
        public void readTxt(string s)
        {
            if (!s.Equals(0))
            {
                if (TypeName[0].Equals("输入条码名称"))        //OP10零件名称1
                {
                    button5.Visible = false;
                    button5.Text = "备用";
                }
                else
                {
                    button5.Visible = true;
                    button5.Text = TypeName[0];
                }
                if (TypeName[1].Equals("输入条码名称"))        //OP10零件名称2
                {
                    button6.Visible = false;
                    button6.Text = "备用";
                }
                else
                {
                    button6.Visible = true;
                    button6.Text = TypeName[1];
                }
                if (TypeName[2].Equals("输入条码名称"))        //OP10零件名称3
                {
                    button22.Visible = false;
                    button22.Text = "备用";
                }
                else
                {
                    button22.Visible = true;
                    button22.Text = TypeName[2];
                }
                if (TypeName[3].Equals("输入条码名称"))        //OP10零件名称4
                {
                    button20.Visible = false;
                    button20.Text = "备用";
                }
                else
                {
                    button20.Visible = true;
                    button20.Text = TypeName[3];
                }
                if (TypeName[4].Equals("输入条码名称"))        //OP20零件名称1
                {
                    button9.Visible = false;
                    button9.Text = "备用";
                }
                else
                {
                    button9.Visible = true;
                    button9.Text = TypeName[4];
                }
                if (TypeName[5].Equals("输入条码名称"))        //OP20零件名称2
                {
                    button10.Visible = false;
                    button10.Text = "备用";
                }
                else
                {
                    button10.Visible = true;
                    button10.Text = TypeName[5];
                }
                if (TypeName[6].Equals("输入条码名称"))        //OP20零件名称3
                {
                    button26.Visible = false;
                    button26.Text = "备用";
                }
                else
                {
                    button26.Visible = true;
                    button26.Text = TypeName[6];
                }
                if (TypeName[7].Equals("输入条码名称"))        //OP20零件名称4
                {
                    button24.Visible = false;
                    button24.Text = "备用";
                }
                else
                {
                    button24.Visible = true;
                    button24.Text = TypeName[7];
                }
                if (TypeName[8].Equals("输入条码名称"))        //OP30零件名称1
                {
                    button11.Visible = false;
                    button11.Text = "备用";
                }
                else
                {
                    button11.Visible = true;
                    button11.Text = TypeName[8];
                }
                if (TypeName[9].Equals("输入条码名称"))        //OP30零件名称2
                {
                    button28.Visible = false;
                    button28.Text = "备用";
                }
                else
                {
                    button28.Visible = true;
                    button28.Text = TypeName[9];
                }
                if (TypeName[10].Equals("输入条码名称"))        //OP30零件名称3
                {
                    button30.Visible = false;
                    button30.Text = "备用";
                }
                else
                {
                    button30.Visible = true;
                    button30.Text = TypeName[10];
                }
                if (TypeName[11].Equals("输入条码名称"))        //OP30零件名称4
                {
                    button32.Visible = false;
                    button32.Text = "备用";
                }
                else
                {
                    button32.Visible = true;
                    button32.Text = TypeName[11];
                }
                if (TypeName[12].Equals("输入条码名称"))        //OP40零件名称1
                {
                    button12.Visible = false;
                    button12.Text = "备用";
                }
                else
                {
                    button12.Visible = true;
                    button12.Text = TypeName[12];
                }
                if (TypeName[13].Equals("输入条码名称"))        //OP40零件名称2
                {
                    button13.Visible = false;
                    button13.Text = "备用";
                }
                else
                {
                    button13.Visible = true;
                    button13.Text = TypeName[13];
                }
                if (TypeName[14].Equals("输入条码名称"))        //OP40零件名称3
                {
                    button14.Visible = false;
                    button14.Text = "备用";
                }
                else
                {
                    button14.Visible = true;
                    button14.Text = TypeName[14];
                }
                if (TypeName[15].Equals("输入条码名称"))        //OP40零件名称4
                {
                    button15.Visible = false;
                    button15.Text = "备用";
                }
                else
                {
                    button15.Visible = true;
                    button15.Text = TypeName[15];
                }
                if (TypeName[16].Equals("输入条码名称"))        //OP50零件名称1
                {
                    button16.Visible = false;
                    button16.Text = "备用";
                }
                else
                {
                    button16.Visible = true;
                    button16.Text = TypeName[16];
                }
                if (TypeName[17].Equals("输入条码名称"))        //OP50零件名称2
                {
                    button17.Visible = false;
                    button17.Text = "备用";
                }
                else
                {
                    button17.Visible = true;
                    button17.Text = TypeName[17];
                }
                if (TypeName[18].Equals("输入条码名称"))        //OP50零件名称3
                {
                    button18.Visible = false;
                    button18.Text = "备用";
                }
                else
                {
                    button18.Visible = true;
                    button18.Text = TypeName[18];
                }
                if (TypeName[19].Equals("输入条码名称"))        //OP50零件名称4
                {
                    button19.Visible = false;
                    button19.Text = "备用";
                }
                else
                {
                    button19.Visible = true;
                    button19.Text = TypeName[19];
                }
                if (TypeName[20].Equals("输入条码名称"))        //OP60零件名称1
                {
                    button21.Visible = false;
                    button21.Text = "备用";
                }
                else
                {
                    button21.Visible = true;
                    button21.Text = TypeName[20];
                }
                if (TypeName[21].Equals("输入条码名称"))        //OP60零件名称2
                {
                    button23.Visible = false;
                    button23.Text = "备用";
                }
                else
                {
                    button23.Visible = true;
                    button23.Text = TypeName[21];
                }
                if (TypeName[22].Equals("输入条码名称"))        //OP60零件名称3
                {
                    button25.Visible = false;
                    button25.Text = "备用";
                }
                else
                {
                    button25.Visible = true;
                    button25.Text = TypeName[22];
                }
                if (TypeName[23].Equals("输入条码名称"))        //OP60零件名称4
                {
                    button33.Visible = false;
                    button33.Text = "备用";
                }
                else
                {
                    button33.Visible = true;
                    button33.Text = TypeName[23];
                }
                //if (TypeName[48].Equals("0"))        //OP70零件名称1
                //{
                button27.Visible = false;
                //}
                //else
                //{
                //    button27.Visible = true;
                //    button27.Text = TypeName[48];
                //}
                //if (TypeName[50].Equals("0"))        //OP70零件名称2
                //{
                button29.Visible = false;
                //}
                //else
                //{
                //    button29.Visible = true;
                //    button29.Text = TypeName[50];
                //}
                //if (TypeName[52].Equals("0"))        //OP70零件名称3
                //{
                button31.Visible = false;
                //}
                //else
                //{
                //    button31.Visible = true;
                //    button31.Text = TypeName[52];
                //}
                //if (TypeName[54].Equals("0"))        //OP70零件名称4
                //{
                button34.Visible = false;
                //}
                //else
                //{
                //    button34.Visible = true;
                //    button34.Text = TypeName[54];
                //}
                if (readSeting[0].Equals("备用"))        //OP10-1零件名称1
                {
                    button37.Visible = false;
                }
                else
                {
                    button37.Visible = true;
                    button37.Text = readSeting[0];
                }
                if (readSeting[2].Equals("备用"))        //OP10-1零件名称2
                {
                    button43.Visible = false;
                }
                else
                {
                    button43.Visible = true;
                    button43.Text = readSeting[2];
                }
                if (readSeting[4].Equals("备用"))        //OP10-2零件名称1
                {
                    button36.Visible = false;
                }
                else
                {
                    button36.Visible = true;
                    button36.Text = readSeting[4];
                }
                if (readSeting[6].Equals("备用"))        //OP10-2零件名称2
                {
                    button35.Visible = false;
                }
                else
                {
                    button35.Visible = true;
                    button35.Text = readSeting[6];
                }
                //if (TypeName[64].Equals("0"))        //预留零件名称1
                //{
                //    button41.Visible = false;
                //}
                //else
                //{
                //    button41.Visible = true;
                //    button41.Text = TypeName[64];
                //}
                //if (TypeName[66].Equals("0"))        //预留零件名称2
                //{
                //    button40.Visible = false;
                //}
                //else
                //{
                //    button40.Visible = true;
                //    button40.Text = TypeName[66];
                //}
                //if (TypeName[68].Equals("0"))        //预留零件名称3
                //{
                //    button39.Visible = false;
                //}
                //else
                //{
                //    button39.Visible = true;
                //    button39.Text = TypeName[68];
                //}
                //if (TypeName[70].Equals("0"))        //预留零件名称4
                //{
                //    button38.Visible = false;
                //}
                //else
                //{
                //    button38.Visible = true;
                //    button38.Text = TypeName[70];
                //}

            }
        }
        //返修完成
        bool[] butDownArry = new bool[40];
        int[] butDownArryCount = new int[40];
        //string[] partName;
        private void button2_Click(object sender, EventArgs e)
        {
            //if (_plcStruct.byte_0 - _plcStruct.byte_1 == 0)
            //{
                //数据记录
                proData.operatorter = Program.userlogin.Admin;//操作员
                StringBuilder stringBuilder = new StringBuilder("");

            int tempi = 0;
            for (int i = 0; i < butDownArry.Length; i++)
            {
                if (butDownArry[i])     //将选中返修的零件剔出来
                {
                    butDownArryCount[tempi] = i;
                    tempi++;
                }
            }
            for (int i = 0; i < tempi; i++)
            {
                //stringBuilder.Append("，" + partName[butDownArryCount[i]]);      //依次记录返修零件名称
                stringBuilder.Append("，" + readSeting[2*butDownArryCount[i]]);      //依次记录返修零件名称
            }

            //string sql = "update repair set([返修完成时间]='{0}',[返修操作员]='{1}',[返修零件名称]='{2}',[返修扫码内容]='{3}') where [ID]='{4}'";
            //sql = string.Format(sql, DateTime.Now, proData.operatorter, stringBuilder.ToString(), label7.Text, /*label20.Text*/ID-1);       //23/6/21可能是无法判断记录到那一条数据中报错，待排查。按下返修完成后会出现报错。
           
            string sql = "update repair set[返修完成时间]='{0}'/*,[返修操作员]='{1}'*/,[返修零件名称]='{2}',[返修扫码内容]='{3}' where [ID]='{4}'";
            sql = string.Format(sql, System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), proData.operatorter, stringBuilder.ToString(), label7.Text, /*label20.Text*/ID);       //string.Format后不需要小括号（），会出现SQL语法错误，                                                                                                                                                                                   //label28.Text = sql;
            num1 = SQLHelp.AddData(sql);
            string sql1 = "update tiaoma set [返修内容] ='{0}'where [内部码] = '{1}'";
            sql1 = string.Format(sql1, label7.Text, label20.Text);
            num2 = SQLHelp.AddData(sql1);
            ////string sql = "update productData set [OP10结果] ='{0}'/*,[内部码]='{1}'*/,[OP10操作时间]='{2}',[OP10螺钉数1]='{3}',[OP10螺钉数2]='{4}',[托盘号]='{5}',[产品型号]='{6}',[返修次数]='{7}' where ID = '{8}'";
            //string sql1 = "update tiaoma set [返修内容] ='{0}'where [内部码] = '{1}'";
            //sql1 = string.Format(sql1, label7.Text, label20.Text);
            //num2 = SQLHelp.AddData(sql1);
            if ((num1 > 0)&&(num2 > 0))     //返修表与结果表记录返修内容后进行初始化
                {
                    button2.BackColor = System.Drawing.Color.Green;
                    proData.save = true;
                    for (int i = 0; i < butDownArry.Length; i++)
                    {
                        butDownArry[i] = false;     //各个按钮清0
                    }
                    button5.BackColor = System.Drawing.Color.Silver;
                    button6.BackColor = System.Drawing.Color.Silver;
                    button9.BackColor = System.Drawing.Color.Silver;
                    button10.BackColor = System.Drawing.Color.Silver;
                    button11.BackColor = System.Drawing.Color.Silver;
                    button28.BackColor = System.Drawing.Color.Silver;
                    button22.BackColor = System.Drawing.Color.Silver;
                    button20.BackColor = System.Drawing.Color.Silver;
                    button26.BackColor = System.Drawing.Color.Silver;
                    button24.BackColor = System.Drawing.Color.Silver;
                    button30.BackColor = System.Drawing.Color.Silver;
                    button32.BackColor = System.Drawing.Color.Silver;
                    button12.BackColor = System.Drawing.Color.Silver;
                    button13.BackColor = System.Drawing.Color.Silver;
                    button14.BackColor = System.Drawing.Color.Silver;
                    button15.BackColor = System.Drawing.Color.Silver;
                    button16.BackColor = System.Drawing.Color.Silver;
                    button17.BackColor = System.Drawing.Color.Silver;
                    button18.BackColor = System.Drawing.Color.Silver;
                    button19.BackColor = System.Drawing.Color.Silver;
                    button21.BackColor = System.Drawing.Color.Silver;
                    button23.BackColor = System.Drawing.Color.Silver;
                    button25.BackColor = System.Drawing.Color.Silver;
                    button33.BackColor = System.Drawing.Color.Silver;
                button27.BackColor = System.Drawing.Color.Silver;
                button29.BackColor = System.Drawing.Color.Silver;
                button37.BackColor = System.Drawing.Color.Silver;
                button43.BackColor = System.Drawing.Color.Silver;
                button41.BackColor = System.Drawing.Color.Silver;
                button40.BackColor = System.Drawing.Color.Silver;
                button31.BackColor = System.Drawing.Color.Silver;
                button34.BackColor = System.Drawing.Color.Silver;
                button36.BackColor = System.Drawing.Color.Silver;
                button35.BackColor = System.Drawing.Color.Silver;
                button39.BackColor = System.Drawing.Color.Silver;
                button38.BackColor = System.Drawing.Color.Silver;
                //label5.Text = "";
                //label5.BackColor = System.Drawing.Color.Silver;
                label6.Text = "";
                    label6.BackColor = System.Drawing.Color.Silver;
                    label7.Text = "";
                    label7.BackColor = System.Drawing.Color.Silver;
                    label20.Text = "";
                    label20.BackColor = System.Drawing.Color.Silver;
                    label1.Text = "";
                    label13.BackColor = System.Drawing.Color.Silver;
                    label28.Text = "";
                }
                else
                {
                    button2.BackColor = System.Drawing.Color.Red;
                } 
            //}
            //else
            //{
            //    MessageBox.Show("退钉数量与打钉数量不相等，不能完成返修！");
            //}
        }
        //int tempButDown;      //确认录入的条码为哪个零件的
        //选择不同工位时打开所选择的工位零件文件
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //readTxt(comboBox1.Text.Contains("OP70") ? "70" : comboBox1.Text.Contains("OP80") ? "80" : comboBox1.Text.Contains("OP100") ? "100" : "0");
        }
        //选择不同型号时打开不同型号的文件
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            readSeting = File.ReadAllLines(Application.StartupPath + "\\" + "型号" + "\\" + comboBox2.Text + ".txt", Encoding.ASCII);
            //readTxt(comboBox2.Text);      //读取txt文件给OP10-1 与OP10-2赋对应的零部件
        }
        private void button5_Click(object sender, EventArgs e)  //单击取反，并变色 /OP10扫码1
        {
            butDownArry[0] = !butDownArry[0];
            button5.BackColor = butDownArry[0]?System.Drawing.Color.Green: System.Drawing.Color.Silver;
            if (butDownArry[0])     //按下(选中)返修button5，返修内容中添加button5的文本
            {
                label7.Text = label7.Text + button5.Text + ",";
            }
        }
       
        private void button6_Click(object sender, EventArgs e)      //OP10扫码2
        {
            butDownArry[1] = !butDownArry[1];
            button6.BackColor = butDownArry[1] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[1])
            {
                label7.Text = label7.Text + button6.Text + ",";
            }
        }

        private void button22_Click(object sender, EventArgs e)     //OP10扫码3
        {
            butDownArry[2] = !butDownArry[2];
            button22.BackColor = butDownArry[2] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[2])
            {
                label7.Text = label7.Text + button22.Text + ",";
            }
        }

        private void button20_Click(object sender, EventArgs e)     //OP10扫码4
        {
            butDownArry[3] = !butDownArry[3];
            button20.BackColor = butDownArry[3] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[3] && label20.Text.Substring(0, 5).Contains("DIDI2"))
            {
                label7.Text = label7.Text + button20.Text + ",";
            }
        }

        private void button9_Click(object sender, EventArgs e)      //OP20扫码1
        {
            butDownArry[4] = !butDownArry[4];
            button9.BackColor = butDownArry[4] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[4])
            {
                label7.Text = label7.Text + button9.Text + ",";
            }
        }

        private void button10_Click(object sender, EventArgs e)      //OP20扫码2
        {
            butDownArry[5] = !butDownArry[5];
            button10.BackColor = butDownArry[5] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[5])
            {
                label7.Text = label7.Text + button10.Text + ",";
            }
        }

        private void button26_Click(object sender, EventArgs e)     //OP20扫码3
        {
            butDownArry[6] = !butDownArry[6];
            button26.BackColor = butDownArry[6] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[6])
            {
                label7.Text = label7.Text + button26.Text + ",";
            }
        }

        private void button24_Click(object sender, EventArgs e)     //OP20扫码4
        {
            butDownArry[7] = !butDownArry[7];
            button24.BackColor = butDownArry[7] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[7])
            {
                label7.Text = label7.Text + button24.Text + ",";
            }
        }

        private void button11_Click(object sender, EventArgs e)      //OP30扫码1
        {
            butDownArry[8] = !butDownArry[8];
            button11.BackColor = butDownArry[8] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[8])
            {
                label7.Text = label7.Text + button11.Text + ",";
            }
        }

        private void button28_Click(object sender, EventArgs e)     //OP30扫码2
        {
            butDownArry[9] = !butDownArry[9];
            button28.BackColor = butDownArry[9] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[9])
            {
                label7.Text = label7.Text + button28.Text + ",";
            }
        }

        private void button30_Click(object sender, EventArgs e)     //OP30扫码3
        {
            butDownArry[10] = !butDownArry[10];
            button30.BackColor = butDownArry[10] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[10])
            {
                label7.Text = label7.Text + button30.Text + ",";
            }
        }

        private void button32_Click(object sender, EventArgs e)     //OP30扫码4
        {
            butDownArry[11] = !butDownArry[11];
            button32.BackColor = butDownArry[11] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[11])
            {
                label7.Text = label7.Text + button32.Text + ",";
            }
        }       

        private void button12_Click(object sender, EventArgs e)      //OP40扫码1
        {
            butDownArry[12] = !butDownArry[12];
            button12.BackColor = butDownArry[12] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[12])
            {
                label7.Text = label7.Text + button12.Text + ",";
            }
        }

        private void button13_Click(object sender, EventArgs e)      //OP40扫码2
        {
            butDownArry[13] = !butDownArry[13];
            button13.BackColor = butDownArry[13] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[13])
            {
                label7.Text = label7.Text + button13.Text + ",";
            }
        }

        private void button14_Click(object sender, EventArgs e)      //OP40扫码3
        {
            butDownArry[14] = !butDownArry[14];
            button14.BackColor = butDownArry[14] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[14])
            {
                label7.Text = label7.Text + button14.Text + ",";
            }
        }

        private void button15_Click(object sender, EventArgs e)      //OP40扫码4
        {
            butDownArry[15] = !butDownArry[15];
            button15.BackColor = butDownArry[15] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[15])
            {
                label7.Text = label7.Text + button15.Text + ",";
            }
        }

        private void button16_Click(object sender, EventArgs e)      //OP50扫码1
        {
            butDownArry[16] = !butDownArry[16];
            button16.BackColor = butDownArry[16] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[16])
            {
                label7.Text = label7.Text + button16.Text + ",";
            }
        }

        private void button17_Click(object sender, EventArgs e)      //OP50扫码2
        {
            butDownArry[17] = !butDownArry[17];
            button17.BackColor = butDownArry[17] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[17])
            {
                label7.Text = label7.Text + button17.Text + ",";
            }
        }

        private void button18_Click(object sender, EventArgs e)      //OP50扫码3
        {
            butDownArry[18] = !butDownArry[18];
            button18.BackColor = butDownArry[18] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[18])
            {
                label7.Text = label7.Text + button18.Text + ",";
            }
        }

        private void button19_Click(object sender, EventArgs e)      //OP50扫码4
        {
            butDownArry[19] = !butDownArry[19];
            button19.BackColor = butDownArry[19] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[19])
            {
                label7.Text = label7.Text + button19.Text + ",";
            }
        }

        private void button21_Click(object sender, EventArgs e)      //OP60扫码1
        {
            butDownArry[20] = !butDownArry[20];
            button21.BackColor = butDownArry[20] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[20])
            {
                label7.Text = label7.Text + button21.Text + ",";
            }
        }

        private void button23_Click(object sender, EventArgs e)      //OP60扫码2
        {
            butDownArry[21] = !butDownArry[21];
            button23.BackColor = butDownArry[21] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[21])
            {
                label7.Text = label7.Text + button23.Text + ",";
            }
        }

        private void button25_Click(object sender, EventArgs e)      //OP60扫码3
        {
            butDownArry[22] = !butDownArry[22];
            button25.BackColor = butDownArry[22] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[22] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button25.Text + ",";
            }
        }

        private void button33_Click(object sender, EventArgs e)     //OP60扫码4
        {
            butDownArry[23] = !butDownArry[23];
            button33.BackColor = butDownArry[23] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[23] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button33.Text + ",";
            }
        }

        private void button27_Click(object sender, EventArgs e)      //OP70扫码1
        {
            butDownArry[24] = !butDownArry[24];
            button27.BackColor = butDownArry[24] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[24] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button27.Text + ",";
            }
        }

        private void button29_Click(object sender, EventArgs e)      //OP70扫码2
        {
            butDownArry[25] = !butDownArry[25];
            button29.BackColor = butDownArry[25] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[25] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button29.Text + ",";
            }
        }

        private void button31_Click(object sender, EventArgs e)      //OP70扫码3
        {
            //tempButDown = 1;
            butDownArry[26] = !butDownArry[26];     //butDownArry[18]取一次反
            button31.BackColor = butDownArry[26] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;    //a = b ? c : d (若b==true,a=c ;若b==false,a=d)
            if (butDownArry[26] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button31.Text + ",";
            }
        }

        private void button34_Click(object sender, EventArgs e)     //OP70扫码4
        {
            butDownArry[27] = !butDownArry[27];     //butDownArry[18]取一次反
            button34.BackColor = butDownArry[27] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;    //a = b ? c : d (若b==true,a=c ;若b==false,a=d)
            if (butDownArry[27] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button34.Text + ",";
            }
        }

        private void button37_Click(object sender, EventArgs e)      //OP10-1扫码1
        {
            //tempButDown = 2;
            butDownArry[28] = !butDownArry[28];
            button37.BackColor = butDownArry[28] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[28] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button37.Text + ",";
            }
        }

        private void button43_Click(object sender, EventArgs e)      //OP10-1扫码2
        {
            //tempButDown = 3;
            butDownArry[29] = !butDownArry[29];
            button43.BackColor = butDownArry[29] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[29] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button43.Text + ",";
            }
        }
        private void button36_Click(object sender, EventArgs e)     //OP10-2扫码1
        {
            butDownArry[30] = !butDownArry[30];
            button36.BackColor = butDownArry[30] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[30] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button36.Text + ",";
            }
        }

        private void button35_Click(object sender, EventArgs e)     //OP10-2扫码2
        {
            butDownArry[31] = !butDownArry[31];
            button35.BackColor = butDownArry[31] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[31] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button35.Text + ",";
            }
        }

        private void button41_Click(object sender, EventArgs e)     //预留扫码1
        {
            butDownArry[32] = !butDownArry[32];
            button41.BackColor = butDownArry[32] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[32] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button41.Text + ",";
            }
        }

        private void button40_Click(object sender, EventArgs e)     //预留扫码2
        {
            butDownArry[33] = !butDownArry[33];
            button40.BackColor = butDownArry[33] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[33] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button40.Text + ",";
            }
        }

        private void button39_Click(object sender, EventArgs e)     //预留扫码3
        {
            butDownArry[34] = !butDownArry[34];
            button39.BackColor = butDownArry[34] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[34] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button39.Text + ",";
            }
        }

        private void button38_Click(object sender, EventArgs e)     //预留扫码4
        {
            butDownArry[35] = !butDownArry[35];
            button38.BackColor = butDownArry[35] ? System.Drawing.Color.Green : System.Drawing.Color.Silver;
            if (butDownArry[35] && (label20.Text.Substring(0, 5).Contains("DIDI2") || label20.Text.Substring(0, 5).Contains("BF") || label20.Text.Substring(0, 5).Contains("BR")))
            {
                label7.Text = label7.Text + button38.Text + ",";
            }
        }
        #region 读取扭力和角度
        #region Gun发送指令函数
        Socket socketSendGun;
        public void GunSend(string str)
        {
            try
            {
                byte[] buffer = new byte[64];
                string[] strTemp = str.Split();
                for (int i = 0; i < strTemp.Length; i++)
                {
                    buffer[i] = Byte.Parse(strTemp[i], System.Globalization.NumberStyles.AllowHexSpecifier);
                }
                socketSendGun.Send(buffer);
            }
            catch
            {

            }
        }
        #endregion
        #region 接收
        void ReciveGan()
        {
            while (true)
            {
                try
                {
                    byte[] buffer = new byte[10240];
                    int r = socketSendGun.Receive(buffer);
                    //实际接收到的有效字节数
                    if (r == 0)
                    {
                        break;
                    }
                    if (buffer != null)
                    {
                        string str1 = "";
                        for (int i = 0; i < buffer.Length; i++)
                        {
                            //为C#中的字符串格式控制符
                            str1 += buffer[i].ToString("X2");//ToString("X2")
                        }
                        //textBox1.Text = stringHextoASCII(str1);
                        string temps = stringHextoASCII(str1);
                        //textBox1.Text = temps.Substring(temps.IndexOf("30237"),29);
                        string tempa = "";
                        if (Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(26)) > 0)
                        {
                            tempa = (temps.Substring(temps.IndexOf("30237"), 29).Substring(16, 5)) + temps.Substring(temps.IndexOf("30237"), 29).Substring(22, Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(27))) + "." + (Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(27)) < 3 ? temps.Substring(temps.IndexOf("30237"), 29).Substring(22 + Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(28)), 3 - Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(28))) : "");
                        }
                        else
                        {
                            tempa = (temps.Substring(temps.IndexOf("30237"), 29).Substring(16, 5 - Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(27)))) + "." + temps.Substring(temps.IndexOf("30237"), 29).Substring(21 - Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(27)), Convert.ToInt32(temps.Substring(temps.IndexOf("30237"), 29).Substring(27))) + temps.Substring(temps.IndexOf("30237"), 29).Substring(22, 3);
                        }
                        label43.Text = tempa;
                        //textBox1.Text += temps.Substring(temps.IndexOf("30238"), 29);
                        string tempb = "";
                        if (Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(26)) > 0)
                        {
                            tempb = (temps.Substring(temps.IndexOf("30238"), 29).Substring(16, 5)) + temps.Substring(temps.IndexOf("30238"), 29).Substring(22, Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(27))) + "." + (Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(27)) < 3 ? temps.Substring(temps.IndexOf("30238"), 29).Substring(22 + Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(28)), 3 - Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(28))) : "");
                        }
                        else
                        {
                            tempb = (temps.Substring(temps.IndexOf("30238"), 29).Substring(16, 5 - Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(27)))) + "." + temps.Substring(temps.IndexOf("30238"), 29).Substring(21 - Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(27)), Convert.ToInt32(temps.Substring(temps.IndexOf("30238"), 29).Substring(27))) + temps.Substring(temps.IndexOf("30238"), 29).Substring(22, 3);
                        }
                        label44.Text = tempb;
                    }

                }
                catch { }

            }
        }
        #endregion
        #region 将16进制的字符串形式转换为对应的ascii码
        public string stringHextoASCII(string s)
        {
            byte[] buff = new byte[s.Length / 2];
            int index = 0;
            for (int i = 0; i < s.Length; i += 2)
            {
                buff[index] = Convert.ToByte(s.Substring(i, 2), 16);
                ++index;
            }
            string result = Encoding.Default.GetString(buff);
            return result;
        }
        #endregion
        #region 链接
        bool gunConnect;
        void gunConnectStart()
        {
            while (gunConnect == false)
            {
                try
                {
                    //创建负责通信的Socket
                    socketSendGun = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    IPAddress ip = IPAddress.Parse("192.168.1.87");
                    IPEndPoint point = new IPEndPoint(ip, 4545);
                    IAsyncResult connResult = socketSendGun.BeginConnect(ip, 4545, null, null);
                    //WaitHandle.WaitOne 方法阻止当前线程，直到当前的 WaitHandle 收到信号
                    connResult.AsyncWaitHandle.WaitOne(2000, true);  //等待2秒

                    if (!connResult.IsCompleted)
                    {
                        socketSendGun.Close();
                        //MessageBox.Show("螺钉枪连接失败");
                    }
                    else
                    {
                        GunSend("30 30 32 30 30 30 30 31 30 30 36 30 30 30 30 30 30 30 30 30 00");
                        GunSend("30 30 36 30 30 30 30 38 30 30 31 30 30 30 30 30 30 30 30 30 31 32 30 31 30 30 31 33 31 31 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 00");
                        gunConnect = true;
                        //MessageBox.Show("连接成功");
                        Thread thGun = new Thread(ReciveGan);
                        thGun.IsBackground = true;
                        thGun.Start();
                    }

                }
                catch
                {
                    MessageBox.Show("螺钉枪连接失败");
                }
                Thread.Sleep(10);
            }
        }
        #endregion

        #endregion

        private void button8_Click(object sender, EventArgs e)      //23/6/27查询就卡死，待调试验证 23/6/28不进行try中的语句能够正常运行。待检验问题。
        {
            //Thread.Sleep(200);
            //string indata = textBox1.Text;
            string indata = label20.Text;
            //if (indata.Substring(0, 4).Contains("DIDI"))
            //{
            button8.Visible = false;
            button7.Visible = true;
            groupBox4.Visible = true;       //查询表格框最外圈
            try
            {
                //ProductData productData = new ProductData();
                //清空表格再查询
                //while (this.dataGridView1.Rows.Count != 1)
                //{
                //    this.dataGridView1.DataSource = null;
                //}
                //string sql = "select [总成码],[总结果], [OP10结果], [内部码], [OP20结果], [OP30结果], [OP40结果],[OP50结果],[OP60结果], [OP70结果],[OP80结果],[OP90结果], [OP100结果], [OP110结果], [OP130人工判定结果] from productData where [内部码] = '{0}'";
                //string sql = "select [总成码],[总结果], [OP10结果], [内部码], [OP20结果], [OP30结果], [OP40结果],[OP50结果],[OP60结果], [OP70结果],[OP80结果],[OP90结果], [OP100结果], [OP100人工判定结果] from productData where [内部码] = '{0}' and [ID] < 10000000";   //ID > 10000000为测试件，不录入查询。where...and...or...哪...且...或...
                //sql = string.Format(sql, label20.Text);
                //SqlDataReader objReader = SQLHelp.GetReader(sql);
                //循环写入数据
                //while (objReader.Read())
                //{
                //    productData.总成码 = objReader["总成码"].ToString();
                //    productData.总结果 = objReader["总结果"].ToString();
                //    productData.OP10结果 = objReader["OP10结果"].ToString();
                //    productData.内部码 = objReader["内部码"].ToString();
                //    //productData.OP10操作员 = objReader["OP10操作员"].ToString();
                //    //productData.OP10操作时间 = objReader["OP10操作时间"].ToString();
                //    productData.OP20结果 = objReader["OP20结果"].ToString();
                //    //productData.OP20操作时间 = objReader["OP20操作时间"].ToString();
                //    //productData.OP20操作员 = objReader["OP20操作员"].ToString();
                //    productData.OP30结果 = objReader["OP30结果"].ToString();
                //    productData.OP40结果 = objReader["OP40结果"].ToString();
                //    //productData.OP40操作时间 = objReader["OP40操作时间"].ToString();
                //    //productData.OP40操作员 = objReader["OP40操作员"].ToString();
                //    productData.OP50结果 = objReader["OP50结果"].ToString();
                //    //productData.OP50操作时间 = objReader["OP50操作时间"].ToString();
                //    //productData.OP50操作员 = objReader["OP50操作员"].ToString();
                //    productData.OP60结果 = objReader["OP60结果"].ToString();
                //    //productData.OP60操作时间 = objReader["OP60操作时间"].ToString();
                //    //productData.OP60操作员 = objReader["OP60操作员"].ToString();
                //    productData.OP70结果 = objReader["OP70结果"].ToString();
                //    //productData.OP70操作时间 = objReader["OP70操作时间"].ToString();
                //    //productData.OP70操作员 = objReader["OP70操作员"].ToString();
                //    productData.OP80结果 = objReader["OP80结果"].ToString();
                //    //productData.OP80操作时间 = objReader["OP80操作时间"].ToString();
                //    //productData.OP80操作员 = objReader["OP80操作员"].ToString();
                //    productData.OP90结果 = objReader["OP90结果"].ToString();
                //    //productData.OP90操作时间 = objReader["OP90操作时间"].ToString();
                //    //productData.OP90操作员 = objReader["OP90操作员"].ToString();
                //    productData.OP100结果 = objReader["OP100结果"].ToString();
                //    //productData.OP100操作时间 = objReader["OP100操作时间"].ToString();
                //    //productData.OP100操作员 = objReader["OP100操作员"].ToString();
                //    //productData.OP110结果 = objReader["OP110结果"].ToString();
                //    //productData.OP130人工判定结果 = objReader["OP130人工判定结果"].ToString();
                //    //productData.OP130操作员 = objReader["OP130操作员"].ToString();
                //    //productData.托盘号 = objReader["托盘号"].ToString();

                //}
                //objReader.Close();
                if (label1.Text/*productData.总成码*/ == "OP70不合格")
                {
                    //气检
                    groupBox5.Visible = true;
                    label27.Visible = true;
                    dataGridView4.Visible = true;
                    List<ProductData> objProductData1 = new List<ProductData>();
                    //查询前先清空数据集
                    objProductData1.Clear();
                    //清空表格再查询
                    while (this.dataGridView4.Rows.Count != 1)
                    {
                        this.dataGridView4.DataSource = null;
                    }
                    
                    string sql1 = "select [产品下线时间], [产品型号], [总成码],[ID],[托盘号],[OP70操作时间],[总结果], [OP70结果], [OP70暖芯正压值], [OP70暖芯负压值], [OP70蒸发器负压值] from productData where [内部码] = '{0}' and [ID] < 10000000";      //ID > 10000000为测试件，不录入查询。where...and...or...哪...且...或...
                    sql1 = string.Format(sql1, label20.Text);
                    SqlDataReader objReader1 = SQLHelp.GetReader(sql1);
                    ProductData productData1 = new ProductData();
                    //循环写入数据


                    while (objReader1.Read())
                    {

                        try
                        {
                            productData1.产品下线时间 = Convert.ToDateTime(objReader1["产品下线时间"]);
                            productData1.产品型号 = objReader1["产品型号"].ToString();
                            //productData1.总成码 = objReader1["总成码"].ToString();
                            //productData1.ID = objReader1["ID"].ToString();
                            //productData1.总结果 = objReader1["总结果"].ToString();
                            productData1.OP70结果 = objReader1["OP70结果"].ToString();
                            productData1.OP70暖芯正压值 = objReader1["OP70暖芯正压值"].ToString();
                            productData1.OP70暖芯负压值 = objReader1["OP70暖芯负压值"].ToString();
                            productData1.OP70蒸发器负压值 = objReader1["OP70蒸发器负压值"].ToString();
                            //productData1.托盘号 = objReader1["托盘号"].ToString();
                            productData1.OP70操作时间 = objReader1["OP70操作时间"].ToString();
                            objProductData1.Add(productData1);
                        }
                        catch
                        {
                            label28.Text = "OP70建立表格赋值错误";
                        }

                    }
                    dataGridView4.AutoGenerateColumns = false;
                    dataGridView4.DataSource = objProductData1;
                    objReader1.Close();
                }
                else if (label1.Text/*productData.总成码*/ == "OP80不合格")
                {
                    //电检
                    label16.Visible = true;       //点击查询按钮后，表格与之对应的按钮显现出来。
                    //string sql2 = "SELECT [产品下线时间],[总成码],[托盘号],[完成时间], [测试时间], A.[产品型号], A.[ID], [操作员], B.[内部码], [电检结果], [鼓风机一档电压], [鼓风机二档电压], [鼓风机三档电压], [鼓风机四档电压], [鼓风机一档电流], [鼓风机二档电流], [鼓风机三档电流], [鼓风机四档电流], [鼓风机一档振动], [鼓风机二档振动], [鼓风机三档振动], [鼓风机四档振动], [鼓风机一档噪音], [鼓风机二档噪音], [鼓风机三档噪音], [鼓风机四档噪音], [左模式-吹面电压], [左模式-吹面电流], [右模式-吹面电压], [右模式-吹面电流], [后模式-吹面电压], [后模式-吹面电流], [左温度-全冷电压], [左温度-全冷电流], [右温度-全冷电压], [右温度-全冷电流], [后温度-全冷电压], [后温度-全冷电流], [循环-内循环电压], [循环-内循环电流], [左模式-吹脚电压], [左模式-吹脚电流], [右模式-吹脚电压], [右模式-吹脚电流], [后模式-吹脚电压], [后模式-吹脚电流], [左温度-全热电压], [左温度-全热电流], [右温度-全热电压], [右温度-全热电流], [后温度-全热电压], [后温度-全热电流], [循环-外循环电压], [循环-外循环电流], [左模式-除霜电压], [左模式-除霜电流], [右模式-除霜电压], [右模式-除霜电流], [后模式-除霜电压], [后模式-除霜电流], [左模式-出厂电压], [左模式-出厂电流], [右模式-出厂电压], [右模式-出厂电流], [后模式-出厂电压], [后模式-出厂电流], [吹面-左吹面风速], [吹面-右吹面风速], [吹面-除霜风速], [吹面-后吹面风速], [吹脚-左吹面风速], [吹脚-右吹面风速], [吹脚-除霜风速], [吹脚-后吹面风速], [除霜-左吹面风速], [除霜-右吹面风速], [除霜-除霜风速], [除霜-后吹面风速], [风速测试占空比], [左吹面温度], [左吹脚温度], [右吹面温度], [右吹脚温度], [后吹面温度], [后吹脚温度], [蒸发器温度], [AQS] FROM OPENROWSET('SQLOLEDB','172.16.150.1';'sa';'943937821',MainData.dbo.productDataToDJ) A JOIN OPENROWSET('SQLOLEDB','172.16.150.1'; 'sa'; '943937821',MainData.dbo.productData) B ON A.ID = B.ID where A.ID = B.ID and [内部码] = '" + textBox1.Text + "'";
                    string sql2 = "SELECT [产品下线时间],[总成码],[托盘号],[完成时间], [测试时间],A.[产品型号], A.[ID], [操作员], B.[内部码], [电检结果], [鼓风机一档电压], [鼓风机二档电压], [鼓风机三档电压], [鼓风机四档电压], [鼓风机一档电流], [鼓风机二档电流], [鼓风机三档电流], [鼓风机四档电流], [鼓风机一档振动], [鼓风机二档振动], [鼓风机三档振动], [鼓风机四档振动], [鼓风机一档噪音], [鼓风机二档噪音], [鼓风机三档噪音], [鼓风机四档噪音], [左模式-吹面电压], [左模式-吹面电流], [右模式-吹面电压], [右模式-吹面电流], [后模式-吹面电压], [后模式-吹面电流], [左温度-全冷电压], [左温度-全冷电流], [右温度-全冷电压], [右温度-全冷电流], [后温度-全冷电压], [后温度-全冷电流], [循环-内循环电压], [循环-内循环电流], [左模式-吹脚电压], [左模式-吹脚电流], [右模式-吹脚电压], [右模式-吹脚电流], [后模式-吹脚电压], [后模式-吹脚电流], [左温度-全热电压], [左温度-全热电流], [右温度-全热电压], [右温度-全热电流], [后温度-全热电压], [后温度-全热电流], [循环-外循环电压], [循环-外循环电流], [左模式-除霜电压], [左模式-除霜电流], [右模式-除霜电压], [右模式-除霜电流], [后模式-除霜电压], [后模式-除霜电流], [左模式-出厂电压], [左模式-出厂电流], [右模式-出厂电压], [右模式-出厂电流], [后模式-出厂电压], [后模式-出厂电流], [吹面-左吹面风速], [吹面-右吹面风速], [吹面-除霜风速], [吹面-后吹面风速], [吹脚-左吹面风速], [吹脚-右吹面风速], [吹脚-除霜风速], [吹脚-后吹面风速], [除霜-左吹面风速], [除霜-右吹面风速], [除霜-除霜风速], [除霜-后吹面风速], [风速测试占空比], [左吹面温度], [左吹脚温度], [右吹面温度], [右吹脚温度], [后吹面温度], [后吹脚温度], [蒸发器温度], [AQS] FROM OPENROWSET('SQLOLEDB','172.16.150.1';'sa';'943937821',MainData.dbo.productDataToDJ) A JOIN OPENROWSET('SQLOLEDB','172.16.150.1'; 'sa'; '943937821',MainData.dbo.productData) B ON A.ID = B.ID where A.ID = B.ID and A.ID < 10000000 and A.[内部码] = '" + indata + "'";
                    if(comboBox2.Text =="DIDI")
                    {
                        dataGridView1.Visible = true;
                        //清空表格再查询
                        while (this.dataGridView1.Rows.Count != 1)
                        {
                            this.dataGridView1.DataSource = null;
                        }
                        dataGridView1.AutoGenerateColumns = false;
                        dataGridView1.DataSource = oductDataToDJFunc.GetData(sql2, true);
                    }
                    //string sqlBDDJ = "SELECT [完成时间], [测试时间],[产品型号], [ID], [内部码], [电检结果], [鼓风机一档电压], [鼓风机二档电压], [鼓风机三档电压], [鼓风机四档电压], [鼓风机一档电流], [鼓风机二档电流], [鼓风机三档电流], [鼓风机四档电流], [鼓风机一档振动], [鼓风机二档振动], [鼓风机三档振动], [鼓风机四档振动], [鼓风机一档噪音], [鼓风机二档噪音], [鼓风机三档噪音], [鼓风机四档噪音], [motor1上极限电压], [motor1上极限电流], [motor1下极限电压], [motor1下极限电流], [motor1模式A电压], [motor1模式A电流], [motor1模式B电压], [motor1模式B电流], [motor1模式C电压], [motor1模式C电流], [motor1模式D电压], [motor1模式D电流], [motor1出厂电压], [motor1出厂电流], [motor2上极限电压], [motor2上极限电流], [motor2下极限电压], [motor2下极限电流], [motor2模式A电压], [motor2模式A电流], [motor2模式B电压], [motor2模式B电流], [motor2模式C电压], [motor2模式C电流], [motor2模式D电压], [motor2模式D电流], [motor2出厂电压], [motor2出厂电流], [motor3上极限电压], [motor3上极限电流], [motor3下极限电压], [motor3下极限电流], [motor3模式A电压], [motor3模式A电流], [motor3模式B电压], [motor3模式B电流], [motor3模式C电压], [motor3模式C电流], [motor3模式D电压], [motor3模式D电流], [motor3出厂电压], [motor3出厂电流], [motor4上极限电压], [motor4上极限电流], [motor4下极限电压], [motor4下极限电流], [motor4模式A电压], [motor4模式A电流], [motor4模式B电压], [motor4模式B电流], [motor4模式C电压], [motor4模式C电流], [motor4模式D电压], [motor4模式D电流], [motor4出厂电压], [motor4出厂电流], [one-1挡风速], [one-2挡风速], [one-3挡风速], [one-4挡风速], [two-1挡风速], [two-2挡风速], [two-3挡风速], [two-4挡风速], [three-1挡风速], [three-2挡风速], [three-3挡风速], [three-4挡风速], [four-1挡风速], [four-2挡风速], [four-3挡风速], [four-4挡风速] FROM productDataToDJ where [内部码] = '" + indata + "'";
                    //if (comboBox2.Text == "百度前空调"||comboBox2.Text == "百度后空调")
                    //{
                    //    dataGridView1.AutoGenerateColumns = false;
                    //    dataGridView1.DataSource = SQLHelpBAIDU.GetDataSetBAIDU(sqlBDDJ).Tables[0];
                    //}
                    else if (comboBox2.Text == "百度前空调" || comboBox2.Text == "百度后空调")
                    {
                        BAIDUdataGridView2.Visible = true;
                        while (this.BAIDUdataGridView2.Rows.Count != 0)
                        {
                            this.BAIDUdataGridView2.DataSource = null;
                        }
                        string sql = "select * from BAIDU.dbo.productDataToDJ where[内部码] = '" + indata + "' order by [完成时间] ASC";
                        string connstr = "server=172.16.150.1;DataBase=BAIDU;Uid=sa;Pwd=943937821";     //server=172.16.150.1;

                        SqlConnection conn = new SqlConnection(connstr);
                        SqlCommand cmd = new SqlCommand(sql, conn);
                        SqlDataAdapter da = new SqlDataAdapter(cmd); //创建数据适配器对象
                        DataSet ds = new DataSet();//创建一个内存数据集

                        conn.Open();
                        da.Fill(ds);  //使用数据适配器填充数据集

                        BAIDUdataGridView2.DataSource = ds.Tables[0];
                    }

                }
                else
                {
                    
                    //综合结果
                    groupBox2.Visible = true;
                    label26.Visible = true;
                    dataGridView3.Visible = true;
                    List<ProductData> objProductData = new List<ProductData>();
                    ProductData productData = new ProductData();
                    //查询前先清空数据集
                    objProductData.Clear();
                    //label1.Text = productData.总成码;
                    while (this.dataGridView3.Rows.Count != 1)
                    {
                        this.dataGridView3.DataSource = null;
                    }
                   
                    string sql = "select [总成码], [总结果], [产品下线时间], [产品型号], [内部码], [OP10-1结果], [OP10-2结果], [OP10结果], [OP20结果], [OP30结果], [OP40结果],[OP50结果],[OP60结果], [OP70结果],[OP80结果],[OP90结果], [OP100结果], [OP100人工判定结果] from productData where [内部码] = '{0}' and [ID] < 10000000";   //ID > 10000000为测试件，不录入查询。where...and...or...哪...且...或...
                    sql = string.Format(sql, label20.Text);
                    SqlDataReader objReader = SQLHelp.GetReader(sql);
                    //循环写入数据
                    while (objReader.Read())
                    {
                        productData.总成码 = objReader["总成码"].ToString();
                        productData.总结果 = objReader["总结果"].ToString();
                        productData.产品下线时间 = Convert.ToDateTime(objReader["产品下线时间"]);
                        productData.产品型号 = objReader["产品型号"].ToString();
                        productData.内部码 = objReader["内部码"].ToString();
                        productData.OP101结果 = objReader["OP10-1结果"].ToString();
                        productData.OP102结果 = objReader["OP10-2结果"].ToString();
                        productData.OP10结果 = objReader["OP10结果"].ToString();
                        //productData.OP10操作员 = objReader["OP10操作员"].ToString();
                        //productData.OP10操作时间 = objReader["OP10操作时间"].ToString();
                        productData.OP20结果 = objReader["OP20结果"].ToString();
                        //productData.OP20操作时间 = objReader["OP20操作时间"].ToString();
                        //productData.OP20操作员 = objReader["OP20操作员"].ToString();
                        productData.OP30结果 = objReader["OP30结果"].ToString();
                        productData.OP40结果 = objReader["OP40结果"].ToString();
                        //productData.OP40操作时间 = objReader["OP40操作时间"].ToString();
                        //productData.OP40操作员 = objReader["OP40操作员"].ToString();
                        productData.OP50结果 = objReader["OP50结果"].ToString();
                        //productData.OP50操作时间 = objReader["OP50操作时间"].ToString();
                        //productData.OP50操作员 = objReader["OP50操作员"].ToString();
                        productData.OP60结果 = objReader["OP60结果"].ToString();
                        //productData.OP60操作时间 = objReader["OP60操作时间"].ToString();
                        //productData.OP60操作员 = objReader["OP60操作员"].ToString();
                        productData.OP70结果 = objReader["OP70结果"].ToString();
                        //productData.OP70操作时间 = objReader["OP70操作时间"].ToString();
                        //productData.OP70操作员 = objReader["OP70操作员"].ToString();
                        productData.OP80结果 = objReader["OP80结果"].ToString();
                        //productData.OP80操作时间 = objReader["OP80操作时间"].ToString();
                        //productData.OP80操作员 = objReader["OP80操作员"].ToString();
                        productData.OP90结果 = objReader["OP90结果"].ToString();
                        //productData.OP90操作时间 = objReader["OP90操作时间"].ToString();
                        //productData.OP90操作员 = objReader["OP90操作员"].ToString();
                        productData.OP100结果 = objReader["OP100结果"].ToString();
                        productData.OP100人工判定结果 = objReader["OP100人工判定结果"].ToString();
                        //productData.OP100操作时间 = objReader["OP100操作时间"].ToString();
                        //productData.OP100操作员 = objReader["OP100操作员"].ToString();
                        //productData.OP110结果 = objReader["OP110结果"].ToString();
                        //productData.OP130人工判定结果 = objReader["OP130人工判定结果"].ToString();
                        //productData.OP130操作员 = objReader["OP130操作员"].ToString();
                        //productData.托盘号 = objReader["托盘号"].ToString();
                        objProductData.Add(productData);

                    }
                    dataGridView3.AutoGenerateColumns = false;
                    dataGridView3.DataSource = objProductData;
                    objReader.Close();
                }

            }
            catch (Exception exa)
            {
                MessageBox.Show(Convert.ToString(exa), "错误提示!");
            }
            //}
            //else
            //{
            //    MessageBox.Show("请检查内部码是否正确！");
            //}
        }

        private void button7_Click(object sender, EventArgs e)      //按下隐藏按钮，隐藏表格与对应的按钮
        {
            
            button7.Visible = false;
            button8.Visible = true;
            //电检
            groupBox4.Visible = false;
            label16.Visible = false;
            dataGridView1.Visible = false;
            //气检
            groupBox5.Visible = false;
            label27.Visible = false;
            dataGridView4.Visible = false;
            //综合结果
            groupBox2.Visible = false;
            label26.Visible = false;
            dataGridView3.Visible = false;
        }

        

    }
}
